package com.wanka.jutou.gateway.config;

import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.wanka.jutou.gateway.rule.GatewayFlowRule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class SentinelConfig {

    @Bean("sentinel-json-gw-flow-converter")
    public Converter<String, List<GatewayFlowRule>> gatewayFlowRuleConverter() {
        return source -> JSON.parseObject(source, new TypeReference<List<GatewayFlowRule>>() {});
    }
}
